package com.blast.comicsisland.adapters;

import android.net.Uri;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.blast.comicsisland.model.commic.commiccontent.Info;
import com.blast.comicsisland.utils.ImageLoaderUtil;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

/**
 * Created by kHRYSTAL on 2015/7/1.
 * Email:jessicastam_love@163.com
 */
public class ContentPagerAdapter extends PagerAdapter{
    private final ImageLoader imageLoader;

    List<Info> infoList;

    public OnImageClickListener listener;
    public ContentPagerAdapter(List<Info> infoList) {
        this.infoList = infoList;
        imageLoader = ImageLoaderUtil.getInstance().getImageLoader();
    }

    public void setListener(OnImageClickListener listener) {
        this.listener = listener;
    }

    @Override
    public int getCount() {
        return infoList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        if (object instanceof NetworkImageView){
            container.removeView((View) object);
        }
    }



    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        String url = infoList.get(position).getImgurl();
        NetworkImageView imageView = new NetworkImageView(container.getContext());
        //imageView.setOnClickListener(listener);
        imageView.setImageUrl(url,imageLoader);
        /*Uri uri = Uri.parse(url);
        imageView.setImageURI(uri);*/
        container.addView(imageView);
        return imageView;
    }

   public interface OnImageClickListener extends View.OnClickListener {
       @Override
       void onClick(View v);
   }
}
